package com.example.userservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.userservice.entity.User;
import com.example.userservice.mapper.UserMapper;
import com.example.userservice.service.UserService;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService { // 该行代码正确

    @Override
    public IPage<User> pageUsers(Integer current, Integer size, Map<String, Object> params) {
        Page<User> page = new Page<>(current, size);
        QueryWrapper<User> wrapper = new QueryWrapper<>();

        // 动态条件查询
        if (params.containsKey("username") && params.get("username") != null) {
            wrapper.like("username", params.get("username"));
        }
        if (params.containsKey("role") && params.get("role") != null) {
            wrapper.eq("role", params.get("role"));
        }

        return page(page, wrapper);
    }
}
